
# REQUIRES: Data/Roper Data.csv

# NOTE: Uses code from Stargazer Package Updates.R instead of the published version of Stargazer. See readme.txt.

################# Dependencies #################
# source("Load Packages.R")
# source("Analysis - Roper/Cleaning.R")

################# Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021 #################
# With question features and percent of options that were for withdrawal
OLS_q <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions,
            data = roper)

# With situation features
OLS_s <- lm(percwithdraw ~  logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
            data = roper)

# With question and situation features
OLS_qs <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
             data = roper)


output <- stargazer(OLS_q, OLS_s, OLS_qs, title="Table 1: Predictors of U.S. Public Support for Withdrawal, 1946-2021",
                    align=TRUE, dep.var.labels=c(""), dep.var.caption="",
                    digits = 3, digits.extra = 0,
                    column.labels=c(" ","",""),
                    notes = "P-value shown in parentheses below coefficient", 
                    notes.append = FALSE,
                    report = "vc*p",
                    covariate.labels=c("Enemy Victory Framing", "Troop Reduction Option", "One-sided Question",
                                       "No. of Response Options", "Log Cumulative Casualties", "Foreign Policy Restraint",
                                       "Vietnam", "Gulf War", "Afghanistan", "Iraq", "Constant"),
                    omit.stat=c("LL","ser","f","adj.rsq"), no.space=TRUE, notes.align="c", out = "Plots/Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html")

webshot("Plots/Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html", "Plots/Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021_R.png", zoom=5, vwidth=580, vheight=600)
# Note: Add the independent variable groups in Word and remove "_R" from the file name
# webshot("Plots/Final Plots/Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021.html", "Plots/Final Plots/Table 1 - Predictors of US Public Support for Withdrawal, 1946-2021.png", zoom=5, vwidth=580, vheight=600)

rm(OLS_q, OLS_qs, OLS_s, output)
